package com.ibeeking.gmc.global.g.rest.controller.v1;

import com.ibeeking.gmc.global.g.rest.service.IAgreementService;
import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.gmc.global.service.common.param.AgreementParam;
import com.ibeeking.gmc.global.service.common.query.AgreementPageQuery;
import com.ibeeking.gmc.global.service.common.vo.AgreementVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 系统协议
 */
@RestController
@RequestMapping("/g/agreement/v1")
public class AgreementController {

    @Resource
    private IAgreementService agreementServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询详情")
    @PostMapping(value = "/view/{id}")
    public AgreementVO view(@PathVariable("id") Long id) {
        return agreementServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "增加")
    @PostMapping(value = "/add")
    public Boolean add(@LoginUser CurrentUser currentUser, @RequestBody @Validated(BaseValidationGroup.Insert.class) AgreementParam agreementParam) {
        agreementParam.setModifyBy(currentUser.getId()).setCreateBy(currentUser.getId());
        return agreementServiceImpl.add(agreementParam);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改")
    @PostMapping(value = "/modify")
    public Boolean modify(@LoginUser CurrentUser currentUser,@RequestBody @Validated(BaseValidationGroup.Update.class) AgreementParam agreementParam) {
        agreementParam.setModifyBy(currentUser.getId());
        return agreementServiceImpl.modify(agreementParam);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改发布状态")
    @PostMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@LoginUser CurrentUser currentUser,@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return agreementServiceImpl.changeStatus(id, status,currentUser.getId());
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除")
    @PostMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return agreementServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "分页查询")
    @PostMapping(value = "/pageList")
    public Page<AgreementVO> pageList(@RequestBody AgreementPageQuery tenantPageQuery) {
        return agreementServiceImpl.pageList(tenantPageQuery);
    }

}
